package com.china08.yxyapi.repository.db;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import com.china08.yxyapi.entity.db.res.YxyResWeikeKnow;

public interface YxyResWeikeKnowRepository extends JpaRepository<YxyResWeikeKnow, String> {

    List<YxyResWeikeKnow> findByKnowOneLevelId(String oneKnowId);

    List<YxyResWeikeKnow> findByKnowTwoLevelId(String towKnowId);

    /**
     * 查询微课关联的知识点
     */
    List<YxyResWeikeKnow> findByWeikeId(String weikeId);

    /**
     * 删除微课关联的知识点
     */
    @Modifying
    @Transactional
    void deleteByWeikeId(String weikeId);

    /**
     * 查询微课关联的某一个知识点
     */
    YxyResWeikeKnow findByWeikeIdAndKnowId(String weikeId, Integer knowThreeId);

    YxyResWeikeKnow findTopByWeikeSubject(String key);

    YxyResWeikeKnow findTopByWeikeSubjectAndWeiKeStatus(String key, int i);

    /**
     * 获取知识点下的微课
     * 
     * @param knowId
     * @return
     */
    List<YxyResWeikeKnow> findTop20ByKnowIdIn(List<Integer> knowId);

    @Query(nativeQuery = true, value = " select distinct know_name from yxy_res.yxy_res_weike_know where know_id = ?1 ")
    Object findDistinctYxyResWeikeKnowByKnowId(Integer valueOf);

    List<YxyResWeikeKnow> findByKnowId(Integer knowId);

}
